package com.river.userdraw;


import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;


/**
 * 用户画像的结果
 *
 * @author riverfan*/
@Data
@NoArgsConstructor
@ToString
public class UserDrawVo implements Serializable {

	private String statTimeDay;
	private String MDN;
	private double male;
	private double female;
	private double age1;
	private double age2;
	private double age3;
	private double age4;
	private double age5;

	/** 性别融合 */
	public void protraitSex(double male2, double female2, long times) {
		double sum = (this.male + this.female + (male2 + female2) * times);
		if(sum != 0){
			this.male = (this.male + male2 * times) / sum;
			this.female = (this.female + female2 * times) / sum;
		}
	}

	/** 年龄段融合 */
	public void protraitAge(double pAge1, double pAge2, double pAge3, double pAge4, double pAge5, long times) {
		double sum = (age1 + age2 + age3 + age4 + age5 )
				+ (pAge1 + pAge2 + pAge3 + pAge4 + pAge5 ) * times;
		if(sum != 0){
			this.age1 = (pAge1 * times + age1) / sum;
			this.age2 = (pAge2 * times + age2) / sum;
			this.age3 = (pAge3 * times + age3) / sum;
			this.age4 = (pAge4 * times + age4) / sum;
			this.age5 = (pAge5 * times + age5) / sum;
		}
	}

	/** 初始化男女概率 */
	public void initSex(float male, float female) {
		float sum = male + female;
		if(sum != 0){
			this.male = male / sum;
			this.female = female / sum;
		}
	}

	/** 初始化年龄段概率 */
	public void initAge(float pAge1, float pAge2, float pAge3, float pAge4, float pAge5) {
		float sum = pAge1 + pAge2 + pAge3 + pAge4 + pAge5;
		if(sum != 0){
			this.age1 = pAge1 / sum;
			this.age2 = pAge2 / sum;
			this.age3 = pAge3 / sum;
			this.age4 = pAge4 / sum;
			this.age5 = pAge5 / sum;
		}
	}


	// 创建画像数据
	 public UserDrawVo(UserInfoVo userInfoVo,
					   float male, float female,
					   float age1, float age2, float age3, float age4, float age5) {

		this.statTimeDay = userInfoVo.getNow();
		this.MDN = userInfoVo.getMobile();
		this.age1 = age1;
		this.age2 = age2;
		this.age3 = age3;
		this.age4 = age4;
		this.age5 = age5;

		// 初始化
		initAge(age1, age2, age3, age4, age5);
		initSex(male, female);
	}



}
